package com.whmnx.chitchat.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


import com.whmnx.chitchat.R;
import com.whmnx.chitchat.main.MainActivity;
import com.whmnx.chitchat.ui.my.ImagePagerActivity;
import com.whmnx.chitchat.utils.ImageUtil;
import com.whmnx.chitchat.view.RoundImageView;
import com.whmnx.chitchat.view.ShowImagesDialog;

import org.apache.commons.lang3.StringEscapeUtils;

import java.util.List;

/**
 * @author Administrator
 */
public class FansImagesAdpter extends BaseAdapter {
    private Context context;
    private List<String> beanList;
    private LayoutInflater inflater;


    public FansImagesAdpter(Context context, List<String> beanList) {
        this.context = context;
        this.beanList = beanList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (beanList.size() > 9){
            return 9;
        }
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return beanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.itme_type_list2,null);
            holder.ivType = convertView.findViewById(R.id.iv_type2);
          //  holder.iv_type2 = (RoundImageView)convertView.findViewById(com.dai.zhenfujin.R.id.iv_type2);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        ImageUtil.setImage(holder.ivType,beanList.get(position));

        holder.ivType.setOnClickListener(v -> {
            ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(v.getMeasuredWidth(), v.getMeasuredHeight());
         //   ShowImagesDialog showImagesDialog = new ShowImagesDialog(context,beanList,position);
          //  showImagesDialog.show();
            ImagePagerActivity.startImagePagerActivity(context, beanList, position, imageSize);
        });

        return convertView;
    }

    class ViewHolder {
        private RoundImageView ivType;
    }
}
